package com.ruoyi.his.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.his.domain.HisPatient;
import com.ruoyi.his.service.IHisPatientService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 挂号收费Controller
 * 
 * @author ruoyi
 * @date 2021-11-04
 */
@RestController
@RequestMapping("/his/patient")
public class HisPatientController extends BaseController
{
    @Autowired
    private IHisPatientService hisPatientService;





    /**
     * 根据病人就诊卡查询病人信息and科室信息
     */
    @PostMapping(value = "/queryHisPatientInfoAndKsByCardId/{cardId}")
    public AjaxResult queryHisPatientInfoAndKsByCardId (@PathVariable("cardId") String cardId)
    {
        return AjaxResult.success(
                "成功!!!",hisPatientService.queryHisPatientInfoAndKsByCardId(cardId)
        );
    }






























    /**
     * 查询挂号收费列表
     */
    @PreAuthorize("@ss.hasPermi('his:patient:list')")
    @GetMapping("/list")
    public TableDataInfo list(HisPatient hisPatient)
    {
        startPage();
        List<HisPatient> list = hisPatientService.selectHisPatientList(hisPatient);
        return getDataTable(list);
    }

    /**
     * 导出挂号收费列表
     */
    @PreAuthorize("@ss.hasPermi('his:patient:export')")
    @Log(title = "挂号收费", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HisPatient hisPatient)
    {
        List<HisPatient> list = hisPatientService.selectHisPatientList(hisPatient);
        ExcelUtil<HisPatient> util = new ExcelUtil<HisPatient>(HisPatient.class);
        return util.exportExcel(list, "挂号收费数据");
    }

    /**
     * 获取挂号收费详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:patient:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(hisPatientService.selectHisPatientById(id));
    }

    /**
     * 新增挂号收费
     */
    @PreAuthorize("@ss.hasPermi('his:patient:add')")
    @Log(title = "挂号收费", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult  add(@RequestBody HisPatient hisPatient)
    {
        int i = hisPatientService.insertHisPatient(hisPatient);
        if(i==-1){
            return AjaxResult.success("该病人信息已存在,不能重复注册");
        }
        return  AjaxResult.success("新增成功");
    }

    /**
     * 修改挂号收费
     */
    @PreAuthorize("@ss.hasPermi('his:patient:edit')")
    @Log(title = "挂号收费", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HisPatient hisPatient)
    {
        return toAjax(hisPatientService.updateHisPatient(hisPatient));
    }

    /**
     * 删除挂号收费
     */
    @PreAuthorize("@ss.hasPermi('his:patient:remove')")
    @Log(title = "挂号收费", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(hisPatientService.deleteHisPatientByIds(ids));
    }
}
